package com.summer.urlmapping.controller;

import org.springframework.context.annotation.Scope;
import org.springframework.dao.DataAccessException;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import com.summer.core.annotations.ScopeType;
import com.summer.core.controller.EntityHome;
import com.summer.core.util.FacesUtil;
import com.summer.urlmapping.model.MetaMapping;

@Component
@Scope(ScopeType.VIEW)
public class MetaMappingHome extends EntityHome<MetaMapping> {
	public static String METAMAPPINGLIST = "/admin/urlMapping/metaMappingList";
	
	@Override
	@Transactional(readOnly = false)
	public String save() {
		try {
			getBaseService().merge(getInstance());
			FacesUtil.addInfoMessage("保存成功！");
		} catch (DataAccessException e) {
			e.printStackTrace();
			FacesUtil.addErrorMessage("保存失败！");
			return null;
		}
		return FacesUtil.redirect(METAMAPPINGLIST);
	}
	
	@Transactional(readOnly = false)
	public String delete(MetaMapping metaMapping) {
		try {
			getBaseService().delete(metaMapping);
			FacesUtil.addInfoMessage("操作成功！");
		} catch (DataAccessException e) {
			e.printStackTrace();
			FacesUtil.addErrorMessage("删除失败！");
			return null;
		}
		return FacesUtil.redirect(METAMAPPINGLIST);
	}
}
